package com.faiz.builder;

/**
 * 建造器模式实例探究
 */
public class Noodle {
    private NoodleSize noodleSize;//面条的粗细
    private int bowlSize;//碗的大小，中，大，超大(0, 1, 2)
    private String flavor;//味道

    public Noodle() {

    }

    public Noodle(Builder builder) {
        this.noodleSize = builder.noodleSize;
        this.bowlSize = builder.bowlSize;
        this.flavor = builder.flavor;
    }

    public static class Builder {
        //必须的参数
        private NoodleSize noodleSize;

        //初始化
        private int bowlSize = 0;
        private String flavor = "麻辣";

        public Builder(NoodleSize noodleSize) {
            this.noodleSize = noodleSize;
        }
        public Builder bowlSize(int bowlSize) {
            this.bowlSize  = bowlSize;
            return this;
        }

        public Builder flavor(String flavor) {
            this.flavor = flavor;
            return this;
        }

        public Noodle build() {
            return new Noodle(this);
        }
    }

    @Override
    public String toString() {
        return "Noodle{" +
                "noodleSize=" + noodleSize +
                ", bowlSize=" + bowlSize +
                ", flavor='" + flavor + '\'' +
                '}';
    }
}
